
//全局函数
export default {

  install(Vue, options) {
    /**
    *  储存localStorage
    */
    Vue.prototype.setlocalStorage = (storeName, storeData) => {
      var storeStr = JSON.stringify(storeData);
      return window.localStorage.setItem(storeName, storeStr);
    },
    /**
    *  获取localStorage
    */
    Vue.prototype.getlocalStorage = (storeName) => {
      var storeName = localStorage.getItem(storeName);
    	return JSON.parse(storeName)
    },
    /**
    *  获取url后面的参数
    */
    Vue.prototype.getUrlParams = (name) => {
      var _reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"),
          _regNext = window.location.search.substr(1).match(_reg);
      if (_regNext != null) return decodeURI(_regNext[2]) || '';
      else return '';
    },
    /**
    *  格式化价格
    */
    Vue.prototype.filterPrice = (price) => {
      if(price){
        return '￥<span class="price-number">'+price.split('.')[0] +'</span>.'+price.split('.')[1];
      }
    },
    /**
    *  跳转外面链接
    */
    Vue.prototype.routeToOut = (url) => {
      window.location.href = url
    },

    /**
    *  打印
    */
    Vue.prototype.log = (obj, type) => {
      type = type || "log";
      const log = JSON.parse(JSON.stringify(obj));
      return console[type](log)
    }

  }
}
